package com.yytek.am.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.yytek.am.domain.FmEvent;
import com.yytek.common.core.domain.R;
import com.yytek.common.security.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yytek.common.log.annotation.Log;
import com.yytek.common.log.enums.BusinessType;
import com.yytek.common.security.annotation.RequiresPermissions;
import com.yytek.am.domain.FmEventHis;
import com.yytek.am.service.IFmEventHisService;
import com.yytek.common.core.web.controller.BaseController;
import com.yytek.common.core.web.domain.AjaxResult;
import com.yytek.common.core.utils.poi.ExcelUtil;
import com.yytek.common.core.web.page.TableDataInfo;

/**
 * 历史告警Controller
 * 
 * @author yytek-iot
 * @date 2022-10-10
 */
@Api(value = "历史告警控制器", tags = {"历史告警管理"})
@RestController
@RequestMapping("/eventHis")
public class FmEventHisController extends BaseController
{
    @Autowired
    private IFmEventHisService fmEventHisService;
    /**
     * 获取各种告警类型数量
     */
    @ApiOperation("获取各种告警类型数量")
    @GetMapping("/allTypeNum")
    public R allTypeNum(FmEventHis fmEventHis)
    {
        Map<String,Object> num = fmEventHisService.selectAllTypeNum(fmEventHis);
        return R.ok(num);
    }

    /**
     * 查询告警事件历史列表
     */
    @ApiOperation("查询告警事件历史列表")
    @RequiresPermissions("am:eventHis:list")
    @GetMapping("/list")
    public TableDataInfo list(FmEventHis fmEventHis)
    {
        startPage();
        List<FmEventHis> list = fmEventHisService.selectFmEventHisList(fmEventHis);
        return getDataTable(list);
    }

    /**
     * 导出告警事件历史列表
     */
    @ApiOperation("导出告警事件历史列表")
    @RequiresPermissions("am:eventHis:export")
    @Log(title = "告警事件历史", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FmEventHis fmEventHis)
    {
        List<FmEventHis> list = fmEventHisService.selectFmEventHisList(fmEventHis);
        ExcelUtil<FmEventHis> util = new ExcelUtil<FmEventHis>(FmEventHis.class);
        util.exportExcel(response, list, "告警事件历史数据");
    }

    /**
     * 获取告警事件历史详细信息
     */
    @ApiOperation("获取告警事件历史详细信息")
    @RequiresPermissions("am:eventHis:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(fmEventHisService.selectFmEventHisById(id));
    }

    /**
     * 新增告警事件历史
     */
    @ApiOperation("新增告警事件历史")
    @RequiresPermissions("am:eventHis:add")
    @Log(title = "告警事件历史", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FmEventHis fmEventHis)
    {
        return toAjax(fmEventHisService.insertFmEventHis(fmEventHis));
    }
    /**
     * 告警历史确认
     */
    @ApiOperation("告警历史确认")
    @RequiresPermissions("am:eventHis:edit")
    @Log(title = "告警历史确认", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/confirm")
    public AjaxResult confirm(@RequestBody FmEventHis fmEventHis)
    {
        //告警确认人
        String userId = SecurityUtils.getUserId().toString();
        fmEventHis.setAckTime(new Date());
        fmEventHis.setAckOperator(userId);
        return toAjax(fmEventHisService.updateFmEventHis(fmEventHis));
    }

    /**
     * 修改告警事件历史
     */
    @ApiOperation("修改告警事件历史")
    @RequiresPermissions("am:eventHis:edit")
    @Log(title = "告警事件历史", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FmEventHis fmEventHis)
    {
        return toAjax(fmEventHisService.updateFmEventHis(fmEventHis));
    }

    /**
     * 删除告警事件历史
     */
    @ApiOperation("删除告警事件历史")
    @RequiresPermissions("am:eventHis:remove")
    @Log(title = "告警事件历史", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(fmEventHisService.deleteFmEventHisByIds(ids));
    }
}
